using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;

namespace Util.DataBase
{
    /// <summary>
    /// 基础数据库访问上下文类
    /// </summary>
    public class BaseDbContext
    {
        /// <summary>
        /// 数据库上下文
        /// 用来处理事务多表查询 和 复杂的操作
        /// </summary>
        public SqlSugarClient dbContext;

        public BaseDbContext()
        {
            dbContext = DbContextFactory.CreateDbContext(true);
        }

        /// <summary>
        /// 开始事务
        /// </summary>
        public void BeginTran()
        {
            dbContext.BeginTran();
        }

        /// <summary>
        /// 提交事务
        /// </summary>
        public void CommitTran()
        {
            dbContext.CommitTran();
        }

        /// <summary>
        /// 回滚事务
        /// </summary>
        public void RollbackTran()
        {
            dbContext.RollbackTran();
        }
    }
}
